
%include 'C:\HSPH\manuscripts\Flourishing and work outcomes\Programs\Revision\Perform_MI_230828.sas'; 
options NOFMTERR;

data table2;
set merged_mi;

proc format;
value age_cat2018c
      1= '30 or below'
	  2= '31-50'
      3= 'above 50';

value gender2018c
      1= 'female'
	  2= 'male';

value race22018c 
      0= 'white (not Hispanic)'
	  1= 'Black/African-American'
	  2= 'Other';

value mart_status2018c
      0= 'Unmarried'
      1= 'Married or in partnership';

value educ2018c
      1= 'high school diploma or eqivalent'
	  2= 'Some college but no degree'
	  3= 'College degree'
      4= 'Graduate school';

value home2018c
      0= 'no'
	  1= 'yes';

value n_children2018c
      0= 'no children'
      1= 'have children';	  

value elders2018c
      0= 'no'
      1= 'yes';	

value work_hours2018c 
      1= '<8h'
      2= '8h'
	  3= '9-10h'
      4= '>10h';

value flsa_type2018c
      1='exempt'
	  2='non-exempt';

value work_home2018d
      0= '0 days/week'
	  1= '1-4 days/week'
	  2= '5 days/week';

value rel_attend2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';    

value community2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  

value volunt2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  
	  
value spirituality2018_r
      0= 'never'
	  1= '<1x/wk'
	  2= '>=1x/wk';  

value vote2018c
      1= 'yes'
	  2= 'no'
      3= 'not a register voter';
run;

proc sort data=table4; by _Imputation_;

******************************************************************************************************
         Indiviudal 2018 flourishing dimensions and 2019 work outcomes, without adjustment of other dimensions
****************************************************************************************************** ;

*1. Emotional health;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= emot_hlth_dim2_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm ; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects emot_hlth_dim2_H2018;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="emot_hlth_dim2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2A.csv";
proc print data=output_linear; run;
ods csv close;

*2. Physical health;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= phys_hlth_dim_H2018
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects phys_hlth_dim_H2018;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="phys_hlth_dim_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2B.csv";
proc print data=output_linear; run;
ods csv close;

*3. Social connectedness;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= social_WB_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects social_WB_H2018 ;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="social_WB_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019 ;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\Users\maggi\Documents\Manuscript\Flourishing and work outcomes\Output;

ods csv file="&path/2. Tables2C.csv";
proc print data=output_linear; run;
ods csv close;

*4. Character strengths;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= char_str_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects char_str_H2018 ;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="char_str_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2D.csv";
proc print data=output_linear; run;
ods csv close;

*5. Financial security;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= financ_WB2_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects financ_WB2_H2018 ;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="financ_WB2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2E.csv";
proc print data=output_linear; run;
ods csv close;

*6. Meaning and purpose;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= purpose_dim2_H2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects purpose_dim2_H2018 ;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="purpose_dim2_H2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2F.csv";
proc print data=output_linear; run;
ods csv close;


*7. Composite score;
%macro linear(outcome);
proc glm data=table2;
class race22018(ref='white (not Hispanic)') age_cat2018c(ref='30 or below') gender2018(ref='female') mart_status2018c(ref='Unmarried') 
vote2018(ref='yes') educ2018c(ref='high school diploma or eqivalent') home2018c(ref='no') n_children2018(ref=first) elders2018c(ref='no')
rel_attend2018_r(ref='never') spirituality2018_r(ref='never') community2018_r(ref='never') volunt2018_r(ref='never') work_hours2018c(ref='<8h')
flsa_type2018(ref='exempt') work_home2018d(ref='0 days/week'); 
model &outcome.= WELL_BEING_eH2018 
                 race22018 age_cat2018c gender2018 mart_status2018c vote2018 educ2018c home2018c n_children2018 
                 elders2018c rel_attend2018_r spirituality2018_r community2018_r volunt2018_r num_health_cond2017 
                 work_hours2018c avg_p502018 flsa_type2018 work_home2018d w_meaning2018 w_recognized2018 w_team2018  
                 distracted2018_r jobsatis2018 w_productive2018/solution clparm; 
by _Imputation_;
title '&outcome.';
format race22018 race22018c. age_cat2018c age_cat2018c. gender2018 gender2018c. mart_status2018c mart_status2018c. vote2018 vote2018c.
educ2018c educ2018c. home2018c home2018c. n_children2018 n_children2018c. elders2018c elders2018c. rel_attend2018_r rel_attend2018_r. work_home2018d work_home2018d.
spirituality2018_r spirituality2018_r. community2018_r community2018_r. volunt2018_r volunt2018_r. work_hours2018c work_hours2018c.  flsa_type2018 flsa_type2018c.;
ods output ParameterEstimates=estimate1;
run;

proc mianalyze parms=estimate1;
modeleffects WELL_BEING_eH2018  ;
ods output parameterestimates=estimate2;
run;

data estimate2;
length outcome $50.;
set estimate2;
outcome="&outcome.";
run;

data output_&outcome.;
set estimate2;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
where Parm="WELL_BEING_eH2018";
run;
  
proc datasets nolist; delete estimate2; run;
%mend;

%linear(outcome=distracted2019_r);
%linear(outcome=jobsatis2019);

data output_linear;
retain outcome Parm Estimate StdErr LCLMean UCLMean Probt;
set output_distracted2019_r output_jobsatis2019;
keep outcome Parm Estimate StdErr LCLMean UCLMean Probt;
run;

%let path=C:\HSPH\manuscripts\Flourishing and work outcomes\Outputs_revision;

ods csv file="&path/2. Table2G.csv";
proc print data=output_linear; run;
ods csv close;
